package JsonProcess;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import Storage.POI;
import android.location.Location;
import android.location.LocationManager;

public class jAllPOIs { // Parse JsonString
	public static ArrayList<POI> process(String jsonText) throws JSONException {
		ArrayList<POI> messagelist = new ArrayList<POI>();
		JSONArray array = new JSONArray(jsonText);

		for (int i = 0; i < array.length(); i++) {
			POI poi = new POI();
			Location location = new Location(LocationManager.GPS_PROVIDER);
			JSONObject object;
			object = (JSONObject) new JSONTokener(array.getString(i))
					.nextValue();
			location.setLatitude(Double.parseDouble(object.getString("lat")));
			location.setLongitude(Double.parseDouble(object.getString("log")));
			poi.setMarkerPhoneNo(object.getString("markerPhoneNumber"));
			poi.setPOIid(object.getString("POIid"));
			poi.setPOITitle(object.getString("POITitle"));
			poi.setMarkerName(object.getString("markerName"));
			poi.setLocation(location);
			poi.setDescription(object.getString("description"));
			poi.setMarkedTime(object.getString("markedTime"));
			poi.setIsHidden(object.getString("isHidden"));		

			messagelist.add(poi);
		}
		return messagelist;
	}

}
